//now we need to get some data and insert it into the tree
//load the list of text and forms from the database
var query = "SELECT id, url_encrypted, created, summary_encrypted, 'textdata' as `table` FROM textdata UNION ALL SELECT id, formurl, created, formtext, 'forms' FROM forms ORDER BY created DESC";
var query = Lazarus.trim(Lazarus.$('tree-search').value);
var sortDirection = Lazarus.$('created').getAttribute("sortDirection");
if (query){
var hashedQuery = Lazarus.hashQuery(query);
//we should really join the two tables, but that's going to have to wait until Lazarus 3.0 (to much work at this point)
rs = Lazarus.db.rs("SELECT id, url_encrypted, created, summary_encrypted, 'textdata' as `table` FROM textdata JOIN textdata_fulltext ON textdata.id = textdata_fulltext.docid WHERE textdata_fulltext.hashed_text MATCH ?1", hashedQuery);
//and search forms as well
var rsForms = Lazarus.db.rs("SELECT id, formurl as url_encrypted, created, formtext as summary_encrypted, 'forms' as `table` FROM forms JOIN forms_fulltext ON forms.id = forms_fulltext.docid WHERE forms_fulltext.hashed_text MATCH ?1", hashedQuery);
//and join the forms with the text
rs = rsForms ? rs.concat(rsForms) : rs;
//and sort in the correct order
rs.sort(function(a, b){
return (a.created > b.created) ? 1 : -1;
});
//if sort is by date desc, then we need to invert the Array
rs = Lazarus.db.rs("SELECT id, url_encrypted, created, summary_encrypted, 'textdata' as `table` FROM textdata UNION ALL SELECT id, formurl, created, formtext, 'forms' FROM forms ORDER BY created"+ desc);
}
//highlight the warning about using full words to search for stuff if there are no results
var classname = (rs.length == 0) ? "warning" : "";